/*
    Created by IntelliJ IDEA.
    @Auther: gaozhe
    @Date: 2020/5/15 上午 9:52
    
*/
package dao.Impl;

import dao.UserDao;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import pojo.User;
import utils.JDBCUtils;


public class UserDaoImpl implements UserDao {
    //创建JDBC工具类对象
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());

    public boolean saveInformation(User user) {
        /**
         * 保存用户信息
         */
        String sql = "insert into tab_user(userName,password,userTel,userPhoto) values(?,?,?,?)";

        int update = jdbcTemplate.update(sql, user.getUserName(),
                user.getPassWord(),
                user.getUserTel(),
                user.getUserPhoto());
        System.out.println(update);
        if (update!=0){
            return true;
        }else {
            return false;
        }

    }


    public User findUserByUsernameAndPassword(String username, String password) {
        System.out.println("UserDaoImpl: "+username+":"+password);
        String sql = "select * from tab_user where userName=? and password =?";
        User user = null;
        try {
            user = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), username, password);
        }catch (Exception e){

        }

        return user;
    }
}
